package com.marry.daodaomanage.ui.security;

import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author mal
 * @date 2022-11-18 17:24
 */
@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setContentType("application/json");
        response.getWriter().write("{\"error\":1,\"msg\":\"需要授权信息\"}");
        response.setStatus(403);

        response.flushBuffer();

    }
}
